package com.tensquare.user.controller;

import com.tensquare.entity.Result;
import com.tensquare.entity.StatusCode;
import com.tensquare.user.pojo.User;
import com.tensquare.user.service.UserService;
import com.tensquare.util.ObjectUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
    * Created by : 大萝卜
    * Date: 2020-4-8        查询param(id)用户
    */
    @RequestMapping(value = "{userId}",method = RequestMethod.GET)
    public Result findUserById(@PathVariable String userId){
        User user = this.userService.findUserById(userId);
        //user 为空
        if (ObjectUtils.isNull(user)){
            log.info("UserController,user为：{}",user.toString());
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
        log.info("UserController,user为：{}",user.toString());
        return new Result(true, StatusCode.OK,"查询成功",user);
    }


}
